#include <string.h>
#include "higv_cextfile.h"
#include "higv_language.h"
#include "sample_utils.h"
#ifdef __cplusplus
#if __cplusplus
    extern "C"{
#endif
#endif /*  __cplusplus  */

HIGV_HANDLE g_menuShow = INVALID_HANDLE;
HI_S32 StartRollAnim(HIGV_HANDLE anim, HIGV_HANDLE widget, HIGV_HANDLE& animObj)
{
    HI_S32 ret = HI_SUCCESS;

    if (animObj == INVALID_HANDLE)
    {
        ret = HI_GV_Anim_CreateInstance(anim, widget, &animObj);
    }

    ret = HI_GV_Anim_Start(ROLL_WIN, animObj);
    return HI_SUCCESS;
}

#define HIGV_CONTROL_PAGENUM   15

static HI_VOID MenuWinList_AddData()
{
    HI_S32 ret;
    HI_U32 index = 0;
    HIGV_HANDLE ddbHandle = 0;
    HIGV_DBROW_S DbRow;

    HI_U32 strSet[HIGV_CONTROL_PAGENUM] = {STR_BUTTON_SCENE, STR_FLING_SCENE, STR_SCROLLBAR_SKIN_SCENE, STR_ASY_MSG_SCENE,
                                           STR_MULTI_LANGUAGE_SCENE, STR_HISTOGRAM_SCENE, STR_SCROLLVIEW_SCENE1, STR_SCROLLVIEW_SCENE2,
                                           STR_ANIM_INOUT, STR_ANIM_WIN_MOVE, STR_ANIM_TAB_INOUT, STR_CLOCK_SCENE, STR_WIN_MENU_ROLL,
                                           STR_ANIM_TEST, STR_IMAGEEX_SCENE
                                          };

    /** Get DDB (default data base) handle*/
    ret = HI_GV_ADM_GetDDBHandle(ADM_SET_STRINGID, &ddbHandle);

    if (ret != HI_SUCCESS)
    {
        printf("Failed to add data, function:<%s>, retval %#x.\n", __FUNCTION__, ret);
        return;
    }

    /** Disable DDB change*/
    HI_GV_DDB_EnableDataChange(ddbHandle, HI_FALSE);

    /** Clear DDB*/
    HI_GV_DDB_Clear(ddbHandle);

    /** Add data*/
    for (index = 0; index < HIGV_CONTROL_PAGENUM; index++)
    {
        memset(&DbRow, 0x00, sizeof(DbRow));
        DbRow.pData = &strSet[index];
        DbRow.Size  = sizeof(HI_U32);
        HI_GV_DDB_Append(ddbHandle, &DbRow);
    }

    /** Enable DDB change*/
    HI_GV_DDB_EnableDataChange(ddbHandle, HI_TRUE);

    HI_GV_Widget_SyncDB(ROLL_WIN_LISTBOX1);

    return;
}

HI_S32 ROLL_WIN_IMAGE1_ontouchaction(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    HI_S32 ret = HI_SUCCESS;

    ret = HI_GV_Widget_Show(MAIN_WIN);
    ret |= HI_GV_Widget_Active(MAIN_WIN);
    ret |= HI_GV_Widget_Hide(ROLL_WIN);

    if (ret != HI_SUCCESS)
    {
        printf("ROLL_WIN_IMAGE1_ontouchaction failed! ret: %x\n", ret);
    }
    return HIGV_PROC_GOON;
}

HI_S32 ROLL_WIN_LISTBOX1_OnAnimStop(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    return HIGV_PROC_GOON;
}

HI_S32 ROLL_WIN_onhide(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    return HIGV_PROC_GOON;
}

HI_S32 ROLL_WIN_onshow(HIGV_HANDLE hWidget,HI_PARAM wParam, HI_PARAM lParam)
{
    MenuWinList_AddData();
    StartRollAnim(animroll_listbox_up, ROLL_WIN_LISTBOX1, g_menuShow);
    return HIGV_PROC_GOON;
}


#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /*  __cplusplus  */
